# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=time
pkgver=1.7
pkgrel=1
pkgdesc="Utility for monitoring a program's use of system resources"
depends=('msys2-runtime')
makedepends=('gcc')
groups=('base')
url='http://www.gnu.org/directory/time.html'
license=('GPL')
arch=('i686' 'x86_64')
intall=time.install
source=(http://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz
        time-1.7-Recompute-CPU-usage-at-microsecond-level.patch
        time-1.7-ru_maxrss-is-in-kilobytes-on-Linux.patch
        time-1.7-cygwin.patch)
md5sums=('e38d2b8b34b1ca259cf7b053caac32b3'
         '096918c20607307de745e6b84201d88b'
         '9832c9e31d4f9d3d44f2af0911b9ffe5'
         '214610b2e6e8fa1368483d0eabc1036f')

prepare() {
  cd "$pkgname-$pkgver"

  # cf https://bugzilla.redhat.com/show_bug.cgi?id=527276
  patch -Np1 < "$srcdir"/time-1.7-Recompute-CPU-usage-at-microsecond-level.patch

  # cf https://bugzilla.redhat.com/show_bug.cgi?id=702826
  patch -Np1 < "$srcdir"/time-1.7-ru_maxrss-is-in-kilobytes-on-Linux.patch

  patch -Np1 < "$srcdir"/time-1.7-cygwin.patch

  # rebuild the ancient autoconf setup to fix a variety of build issues
  # surrounding missing/incorrect includes.
  autoreconf -fisv
}

build() {
  cd "$srcdir/$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --infodir=/usr/share/info \
    --build=${CHOST}
  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  make exec_prefix="$pkgdir/usr" infodir="$pkgdir/usr/share/info" install
}
